﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace Hardanger.Features.ServerFuzzer.DetectionEngine
{
    static class DetectionEngineFactory
    {
        public static ObservableCollection<string> GetAllDetectionEngines()
        {
            return new ObservableCollection<string>(
            AppDomain.CurrentDomain.GetAssemblies().ToList()
                .SelectMany(s => s.GetTypes())
                .Where(p => typeof(IDetectionEngine).IsAssignableFrom(p) && !p.IsInterface)
                .Select(c => c.Name).ToList());
        }
        public static IDetectionEngine Create(string name)
        {
            var engine = AppDomain.CurrentDomain.GetAssemblies().ToList()
                .SelectMany(s => s.GetTypes())
                .Where(t => typeof(IDetectionEngine).IsAssignableFrom(t) && t.Name == name).SingleOrDefault(); //Throw an error if more than one found

            return (IDetectionEngine)System.Activator.CreateInstance(Type.GetType(engine.FullName));
        }
    }
}
